package com.baiyang.server.config;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.springframework.security.access.AccessDecisionVoter;
import org.springframework.security.access.ConfigAttribute;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.web.FilterInvocation;

import com.baiyang.server.config.provider.UserDetail;
/**
 * {
 * 	int ACCESS_GRANTED = 1;  -- 通过
 *  int ACCESS_ABSTAIN = 0;  -- 弃权
 *  int ACCESS_DENIED = -1;  -- 否定
 * }
 * @author XVX
 *
 */
public class RoleBasedVoter implements AccessDecisionVoter<Object> {

	@Override
	public boolean supports(ConfigAttribute attribute) {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	public boolean supports(Class<?> clazz) {
		// TODO Auto-generated method stub
		return true;
	}
	
	/**
	 * 权限控制
	 */
	@Override
	public int vote(Authentication authentication, Object object, Collection<ConfigAttribute> attributes) {
		// TODO Auto-generated method stub
		FilterInvocation filterInvocation = (FilterInvocation) object;
		String url = filterInvocation.getRequestUrl();
		System.err.println("vote---->" + authentication.getAuthorities());
		Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
		if(url.equals("/userOperation/getVerPic")) {
			return 1;
		}else {
			return 1;
		}
	}

}
